<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <script src="add.js" type="module"></script> -->
    <!-- <script src="sub.js" type="module"></script> -->
</head>
    <button id="btn">导入</button>
    <script type="module">
        import y,{a as x,add} from "./add.js"
        console.log("a是"+x)
        let re=add()
        console.log("a+200的结果是"+re)
        //js模块化后，其内部的变量和方法外界无法访问
        // import y from './add.js'
        console.log("add.js的默认导出是"+y)

        //动态导入
        let btn=document.getElementById("btn")
        btn.addEventListener("click",()=>{
            let sub=import("./sub.js")
            sub.then((module)=>{
                console.log("你按了一下按钮然后"+module.b)
                console.log("再然后"+module.sub())
            })

        })
    </script>
</body>
</html>